<template>
    
    脚本导入私钥的地址为： {{address}}
    <button @click="connectProvider">连接provider</button>
    浏览器提供的provider的链id为 {{chainId}}
</template>
<script setup lang="ts">
import { BrowserProvider } from "ethers";
import { Wallet ,} from "ethers";
import {onMounted, ref} from 'vue'
let address=ref('')
let chainId=ref(0)

// 通过私钥创建钱包
let MyWallet=new Wallet('538a37ae37ff7fda6fa3c95637bc73695e13b3b3764eb55e067f9004c4fb93c3')
onMounted(async ()=>{
// 打印账户地址
address.value= await MyWallet.getAddress()
console.log(address.value)
})


     function connectProvider(){
// 连接provider
const provider=new BrowserProvider(window.ethereum)
MyWallet=MyWallet.connect(provider)
MyWallet.getChainId().then((rs)=>{
chainId.value=rs
})
console.log('链id为'+chainId.value)
    }
</script>




<!-- <template>
    aaaaaaaa
</template>
<script setup lang="ts">

</script> -->